<template>
	<up-navbar bgColor="#082032" :border="true" placeholder :safeAreaInsetTop="false">
		<template #left>
			<view class="navbar-left">
				log
			</view>
		</template>
		<template #right>
			<view class="navbar-right">
				0 Points
			</view>
			<view class="avatar radius200 mar-left-16"></view>
		</template>
	</up-navbar>

	<view class="pad-32">
		<view class="color-fff font-48 font-w-600">AI Tools</view>
		<view class="color-grey font-28">Lorem ipsum dolor sit amet</view>
		<view class="mar-top-24">
			<view class="list pad-bottom-32" @click="hanldeChat">
				<image class="banner " src="../../static/images/img.jpg"></image>
				<view class="font-32 color-fff mar-top-8 font-w-600">magic animation</view>
			</view>
			<view class="list pad-bottom-32">
				<image class="banner" src="../../static/images/img.jpg"></image>
				<view class="font-32 color-fff mar-top-8 font-w-600">Dancing Generation</view>
			</view>
		</view>

		<view class="color-fff font-48 font-w-600">AI Tools</view>
		<view class="color-grey font-28">Lorem ipsum dolor sit amet</view>
	</view>

	<up-waterfall v-model="flowList" ref="uWaterfallRef">
		<template v-slot:left="{leftList}">
			<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
				<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
				<up-lazy-load threshold="-350" :image="item.image" :index="index"></up-lazy-load>
			</view>
		</template>
		<template v-slot:right="{rightList}">
			<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
				<up-lazy-load threshold="-350" :image="item.image" :index="index"></up-lazy-load>
			</view>
		</template>
	</up-waterfall>
</template>

<script>
	export default {
		data() {
			return {
				loadStatus: 'loadmore',
				flowList: [],
				list: [{
						price: 35,
						title: '北国风光，千里冰封，万里雪飘',
						shop: '李白杜甫白居易旗舰店',
						image: '../../static/images/list1.png',
					},
					{
						price: 75,
						title: '望长城内外，惟余莽莽',
						shop: '李白杜甫白居易旗舰店',
						image: '../../static/images/list2.png',
					},
					{
						price: 385,
						title: '大河上下，顿失滔滔',
						shop: '李白杜甫白居易旗舰店',
						image: '../../static/images/list3.png',
					},
					{
						price: 784,
						title: '欲与天公试比高',
						shop: '李白杜甫白居易旗舰店',
						image: '../../static/images/list4.png',
					},
					{
						price: 7891,
						title: '须晴日，看红装素裹，分外妖娆',
						shop: '李白杜甫白居易旗舰店',
						image: '../../static/images/list5.png',
					},
					{
						price: 2341,
						shop: '李白杜甫白居易旗舰店',
						title: '江山如此多娇，引无数英雄竞折腰',
						image: '../../static/images/list6.png',
					},
				]
			}
		},
		onLoad() {
			this.addRandomData();
		},
		onReachBottom() {
			this.loadStatus = 'loading';
			// 模拟数据加载
			setTimeout(() => {
				this.addRandomData();
				this.loadStatus = 'loadmore';
			}, 1000)
		},
		methods: {
			// 跳转聊天
			hanldeChat(){
				uni.switchTab({
					url: '/pages/chatList/chatList'
				})
			},
			addRandomData() {
				for (let i = 0; i < 10; i++) {
					let index = this.$u.random(0, this.list.length - 1);
					// 先转成字符串再转成对象，避免数组对象引用导致数据混乱
					let item = JSON.parse(JSON.stringify(this.list[index]))
					item.id = this.$u.guid();
					this.flowList.push(item);
				}
			},
			clear() {
				this.$refs.uWaterfallRef.clear();
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		background: #082032;
	}

	.navbar-left {
		color: #727C86;
	}

	.navbar-right {
		color: #727C86;
	}

	.avatar {
		width: 56rpx;
		height: 56rpx;
		background: #5E646A;
	}

	.banner {
		display: block;
		width: 100%;
		height: 384rpx;
	}


	.demo-warter {
		margin: 5px;
		position: relative;
	}

	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}

	.demo-image {
		width: 100%;
	}

</style>